package com.dylan.springcloud.clientb.controller;

import com.dylan.springcloud.common.util.LogUtil;
import com.dylan.springcloud.common.util.SleepUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.rmi.runtime.Log;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Dylan on 2018/10/15.
 */
@RestController
public class TestController {

    @Value("${sleep.second}")
    private int sleepSecond;

    @GetMapping("/sub")
    public String add(Integer a, Integer b, HttpServletRequest request) {
        LogUtil.info("接收请求：a=" + a + ",b=" + b);
        String result = " From Port: "+ request.getServerPort() + ", Result: " + (a - b) + ".时间：" + System.currentTimeMillis();
        if (sleepSecond != 0) {
            System.out.println("睡眠" + sleepSecond + "秒");
            SleepUtils.seconds(sleepSecond);
        }
        LogUtil.info(result);
        return result;
    }

}
